home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / ClickArea.java < prev    next >
Text File  |  1998-09-15  |  4KB  |  102 lines

  1. /*
  2.  * @(#)ClickArea.java    1.8 98/03/18
  3.  *
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  *
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  *
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30.  
  31. import java.awt.Graphics;
  32.  
  33. /**
  34.  * An click feedback ImageArea class.
  35.  * This class extends the basic ImageArea Class to show the locations
  36.  * of clicks in the image in the status message area.  This utility
  37.  * ImageArea class is useful when setting up ImageMaps.
  38.  *
  39.  * @author     Jim Graham
  40.  * @version     1.8, 03/18/98
  41.  */
  42. class ClickArea extends ImageMapArea {
  43.     /** The X location of the last mouse press. */
  44.     int startx;
  45.     /** The Y location of the last mouse press. */
  46.     int starty;
  47.     /** A boolean to indicate whether we are currently being dragged. */
  48.     boolean dragging;
  49.  
  50.     static String ptstr(int x, int y) {
  51.     return "("+x+", "+y+")";
  52.     }
  53.  
  54.     /**
  55.      * When the user presses the mouse button, start showing coordinate
  56.      * feedback in the status message line.
  57.      */
  58.     public boolean press(int x, int y) {
  59.     showStatus("Clicked at "+ptstr(x, y));
  60.     startx = x;
  61.     starty = y;
  62.     dragging = true;
  63.     return false;
  64.     }
  65.  
  66.     /**
  67.      * Update the coordinate feedback every time the user moves the mouse
  68.      * while he has the button pressed.
  69.      */
  70.     public boolean drag(int x, int y) {
  71.     showStatus("Rectangle from "+ptstr(startx, starty)
  72.            +" to "+ptstr(x, y)
  73.            +" is "+(x-startx)+"x"+(y-starty));
  74.     return false;
  75.     }
  76.  
  77.     /**
  78.      * Update the coordinate feedback one last time when the user releases
  79.      * the mouse button.
  80.      */
  81.     public boolean lift(int x, int y) {
  82.     dragging = false;
  83.     return drag(x, y);
  84.     }
  85.  
  86.     /**
  87.      * This utility method returns the status string this area wants to
  88.      * put into the status bar.  If this area is currently animating
  89.      * a message, then that message takes precedence over any other area
  90.      * that a higher stacked area may want to display, otherwise the
  91.      * message from the higher stacked area takes precedence.
  92.      */
  93.     public String getStatus(String prevmsg) {
  94.     if (dragging) {
  95.         return (status != null) ? status : prevmsg;
  96.     } else {
  97.         return (prevmsg == null) ? status : prevmsg;
  98.     }
  99.     }
  100. }
  101.  
  102.